package org.ala.tiktools.generator.mybatis.creator.order_by;

import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ala
 * @date 2025-01-13 14:54
 */
public class OrderByInfo {

    protected EntityInfo e;
    protected TableInfo t;

    protected String pkg;
    protected String className;
    protected List<String> imports = new ArrayList<>();
    protected String parent;
    protected String parentName;

    protected String comparator;
    protected String comparatorClassName;

    protected List<OrderByFieldInfo> fields;

    public static OrderByInfo build(Part p, TableInfo t, EntityInfo e) {
        OrderByInfo ob = new OrderByInfo();

        ob.e = e;
        ob.t = t;

        ob.pkg = p.getOut().getOrderBy().getPkg();
        ob.className = Tools.lowToUpFirst(Tools.hump(t.getName())) + p.getOut().getOrderBy().getSuffix();

        ob.parent = p.getOut().getOrderBy().getParent();
        String[] ss = ob.parent.split("\\.");
        ob.parentName = ss[ss.length-1];

        ob.comparator = p.getOut().getOrderBy().getComparator();
        ob.comparatorClassName = Tools.parseClassName(ob.comparator);

        ob.fields = t.getColumns().stream().map(c -> OrderByFieldInfo.build(Tools.lowToUpFirst(Tools.hump(c.getName())), c.getName())).collect(Collectors.toList());

        return ob;
    }

    public EntityInfo getE() {
        return e;
    }

    public void setE(EntityInfo e) {
        this.e = e;
    }

    public TableInfo getT() {
        return t;
    }

    public void setT(TableInfo t) {
        this.t = t;
    }

    public String getPkg() {
        return pkg;
    }
    public void setPkg(String pkg) {
        this.pkg = pkg;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public List<OrderByFieldInfo> getFields() {
        return fields;
    }

    public void setFields(List<OrderByFieldInfo> fields) {
        this.fields = fields;
    }

    public List<String> getImports() {
        return imports;
    }

    public void setImports(List<String> imports) {
        this.imports = imports;
    }

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public String getComparator() {
        return comparator;
    }

    public void setComparator(String comparator) {
        this.comparator = comparator;
    }

    public String getComparatorClassName() {
        return comparatorClassName;
    }

    public void setComparatorClassName(String comparatorClassName) {
        this.comparatorClassName = comparatorClassName;
    }
}
